<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

if($_RQ['op']=='list'){	
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['storeid'])){
		$params['id']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 100;
	$total='';
	$fields=array('id','uniacid','title','status');
	$list=pdo_getslice('jy_yxw_store',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$nowyue = mktime(0,0,0,date('m'),1,date('Y'));
		$yesyue = mktime(0,0,0,date('m')-1,1,date('Y'));
		foreach($list as &$item){
			$item['allfee']=pdo_getsum('jy_yxw_infee_log',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'storeid'=>$item['id']),'fee');
			$item['totle']=pdo_count('jy_yxw_infee_log',array('uniacid'=>$_SESSION['uniacid'],'type'=>1,'status'=>1,'storeid'=>$item['id']),'id');
			$item['now']=pdo_getsum('jy_yxw_infee_log',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'storeid'=>$item['id'],'createtime >'=>$nowyue),'fee');
			$item['yes']=pdo_getsum('jy_yxw_infee_log',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'storeid'=>$item['id'],'createtime >'=>$yesyue),'fee');
		}
	}
	paixu($list,'allfee','desc');
	foreach($list as $k=>&$lv){
		$lv['rank']=$k+1;
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',		
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
			array('name'=>'rank','title'=>'排名','type'=>'string'),
			array('name'=>'title','title'=>'门店','type'=>'string'),
			array('name'=>'allfee','title'=>'总成交金额','type'=>'string'),
			array('name'=>'totle','title'=>'总成交用户','type'=>'string'),
			array('name'=>'now','title'=>'当月业绩','type'=>'string'),
			array('name'=>'yes','title'=>'上月业绩','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'storeid','width'=>15,'title'=>'选择门店','type'=>'select','options'=>'store'),
		)
	);
	$return['store']=pdo_getall('jy_yxw_store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['htmls']=$htmls;
	exi($return);
}
